package cc.wsyw126.java.test;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Set;
import java.util.TreeSet;

/**
 * Created by junpeng.yang on 16/10/26.
 */
public class millionNumber {
    public static void main(String[] args) throws InterruptedException {
        int n = 100000, n2 = 50000;
        useLinkedList(n, n2);
        System.out.println("sleep end = " + "sleep end");
        useArrayList(n, n2);

    }

    private static void useArrayList(int n, int n2) {
        long start = System.currentTimeMillis();
        ArrayList<Integer> local = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            local.add(i);
        }
        System.out.println("(start -System.currentTimeMillis() = " + (start - System.currentTimeMillis()));
        start = System.currentTimeMillis();
        ArrayList<Integer> remote = new ArrayList<>();
        for (int i = 0; i < n2; i++) {
            remote.add(i);
        }
        System.out.println("(start -System.currentTimeMillis() = " + (start - System.currentTimeMillis()));

        start = System.currentTimeMillis();
        ArrayList<Integer> same = new ArrayList<>(local);
        same.retainAll(remote);
        remote.removeAll(same);
        local.removeAll(same);
        System.out.println("(start -System.currentTimeMillis() = " + (start - System.currentTimeMillis()));
    }

    private static void useLinkedList(int n, int n2) {
        long start = System.currentTimeMillis();
        LinkedList<Integer> local = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            local.add(i);
        }
        System.out.println("(start -System.currentTimeMillis() = " + (start - System.currentTimeMillis()));
        start = System.currentTimeMillis();
        LinkedList<Integer> remote = new LinkedList<>();
        for (int i = 0; i < n2; i++) {
            remote.add(i);
        }
        System.out.println("(start -System.currentTimeMillis() = " + (start - System.currentTimeMillis()));

        start = System.currentTimeMillis();
        LinkedList<Integer> same = new LinkedList<>(local);
        same.retainAll(remote);
        remote.removeAll(same);
        local.removeAll(same);
        System.out.println("(start -System.currentTimeMillis() = " + (start - System.currentTimeMillis()));
        System.out.println("UserLinkedList end");
    }

    private static void useTreeSet(int n, int n2) {
        long start = System.currentTimeMillis();
        TreeSet<Integer> local = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            local.add(i);
        }
        System.out.println("(start -System.currentTimeMillis() = " + (start - System.currentTimeMillis()));
        start = System.currentTimeMillis();
        TreeSet<Integer> remote = new TreeSet<>();
        for (int i = 0; i < n2; i++) {
            remote.add(i);
        }
        System.out.println("(start -System.currentTimeMillis() = " + (start - System.currentTimeMillis()));

        start = System.currentTimeMillis();
        TreeSet<Integer> same = new TreeSet<>(local);
        same.retainAll(remote);
        remote.removeAll(same);
        local.removeAll(same);
        System.out.println("(start -System.currentTimeMillis() = " + (start - System.currentTimeMillis()));
        System.out.println("UserLinkedList end");
    }
}
